<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const arr = [
        {
            "children": [
                {
                    "id": 316,
                    "companyId": 1518,
                    "itemId": 3227,
                    "itemChildId": 4021,
                    "itemChildNum": 1,
                    "createdBy": 3049,
                    "createdTime": 1642427108000,
                    "itemType": 1,
                    "withinCode": "7567456",
                    "outerCode": "7245356",
                    "minUnitName": "个",
                    "minUnit": null,
                    "propertiesName": "默认单规格:钢化",
                    "itemCategoryName": "手机数码",
                    "itemChildName": "手机膜",
                    "itemChildCode": "P12345689436001",
                    "itemSoldPrice": 4900,
                    "itemSkuDiyCode": null,
                    "skuCode": "P12345689436001",
                    "itemGoodsNumber": null,
                    "itemChildStoreName": null,
                    "hasSerialNumber": null,
                    "inoutPriceDec": 20,
                    "orginalImageUrl": null,
                    "decimalInventory": 100,
                    "orderNo": null,
                    "childItem": null,
                    "childsku": null,
                    "outSum": null,
                    "residueNum": null,
                    "outPrice": 20,
                    "batchNumber": null,
                    "parentSkuId": 3934,
                    "storeId": null,
                    "childItemId": null,
                    "snsNumber": 100,
                    "itemChildTotalPrice": 100,
                    "itemChildCount": 5,
                    "itemChildPrice": 20
                },
                {
                    "id": 317,
                    "companyId": 1518,
                    "itemId": 3227,
                    "itemChildId": 3931,
                    "itemChildNum": 1,
                    "createdBy": 3049,
                    "createdTime": 1642427108000,
                    "itemType": 1,
                    "withinCode": "876864757",
                    "outerCode": "568357356",
                    "minUnitName": "件",
                    "minUnit": null,
                    "propertiesName": "默认单规格:米白",
                    "itemCategoryName": "手机壳",
                    "itemChildName": "手机壳",
                    "itemChildCode": "P12345689165001",
                    "itemSoldPrice": 3600,
                    "itemSkuDiyCode": null,
                    "skuCode": "P12345689165001",
                    "itemGoodsNumber": null,
                    "itemChildStoreName": null,
                    "hasSerialNumber": null,
                    "inoutPriceDec": 12,
                    "orginalImageUrl": null,
                    "decimalInventory": 100,
                    "orderNo": null,
                    "childItem": null,
                    "childsku": null,
                    "outSum": null,
                    "residueNum": null,
                    "outPrice": 0,
                    "batchNumber": null,
                    "parentSkuId": 3934,
                    "storeId": null,
                    "childItemId": null,
                    "snsNumber": 100,
                    "itemChildTotalPrice": 60,
                    "itemChildCount": 5,
                    "itemChildPrice": 12
                },
                {
                    "id": 318,
                    "companyId": 1518,
                    "itemId": 3227,
                    "itemChildId": 3932,
                    "itemChildNum": 1,
                    "createdBy": 3049,
                    "createdTime": 1642427108000,
                    "itemType": 1,
                    "withinCode": "85675757",
                    "outerCode": "5675474567",
                    "minUnitName": "块",
                    "minUnit": null,
                    "propertiesName": "默认单规格:黑色6000ma",
                    "itemCategoryName": "手机数码",
                    "itemChildName": "手机电池",
                    "itemChildCode": "P12345689166001",
                    "itemSoldPrice": 43200,
                    "itemSkuDiyCode": null,
                    "skuCode": "P12345689166001",
                    "itemGoodsNumber": null,
                    "itemChildStoreName": null,
                    "hasSerialNumber": null,
                    "inoutPriceDec": 122,
                    "orginalImageUrl": null,
                    "decimalInventory": 100,
                    "orderNo": null,
                    "childItem": null,
                    "childsku": null,
                    "outSum": null,
                    "residueNum": null,
                    "outPrice": 103.04,
                    "batchNumber": null,
                    "parentSkuId": 3934,
                    "storeId": null,
                    "childItemId": null,
                    "snsNumber": 100,
                    "itemChildTotalPrice": 610,
                    "itemChildCount": 5,
                    "itemChildPrice": 122
                }
            ],
            "indexNumber": 1,
            "snsNumber": 0,
            "itemCategoryName": "手机数码",
            "itemId": 3227,
            "skuId": 3934,
            "decimalInventory": 100,
            "decimalNum": 5,
            "num": 0,
            "inoutPrice": 15400,
            "inoutPriceDec": 154,
            "itemTitle": "VIVO手机",
            "itemType": 6,
            "skuCode": "P12345689168001",
            "propertiesName": "默认单规格:米白",
            "minUnitName": "台",
            "imageUrl": "39deffd5706945a0b5dffa17a6b19df5",
            "soldPrice": 15400,
            "totalPrice": 770,
            "itemCode": "P12345689168",
            "id": 3851,
            "withinCode": "67836456",
            "batchNumber": "",
            "processingCharges": 0,
            "producedDate": null,
            "expiringDate": null,
            "allNum": null,
            "currentFocusInput": ""
        }
    ];

    arr.find((item, index) => {
        if (item.children && item.children.length) {
            item.children.find((subItem, subIndex) => {
                // 库存
                const allNum = subItem.decimalInventory || 0;
                // 存在的序列号数
                const snsNumber = subItem.snsNumber || 0;
                // 无序列号数
                const noSnsNum = allNum - snsNumber;
                // 已选的序列号数
                let serialLength;
                try {
                    serialLength = subItem.serialNumbers.split(',').length;
                } catch (e) {
                    serialLength = 0;
                }
                // 出库数 > 选择的序列号数 + 无序列号数
                if (subItem.itemChildCount > serialLength + noSnsNum) {
                    console.log(`第${index + 1}条组合商品中第${subIndex + 1}条子商品，请至少新增${subItem.itemChildCount - noSnsNum}条序列号`);
                    return true;
                }
            });
        }
    })
</script>
</body>
</html>
